<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>检查数量</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<div id="msg" align="center" style="padding-top: 40px;">
		正在验证物料编码……</div>
	<script type="text/javascript">
		var upWindow = window.parent.frames["zwIframe"];
		var designClass = "design_class", hideClass = "hide_class", browseClass = "browse_class", addClass = "add_class", editClass = "edit_class";

		function fy_dialog_close() {
			window.parent.$(".mask").remove();
			window.parent.parent.$(".layui-layer-iframe").parent().find(".layui-layer-close").trigger("click");
		}
		function getUpFieldsByFieldval(name) {
			return upWindow.$("[fieldval*='displayName:\"" + name + "\"']");
		}

		function getUpFieldValue(field) {
			var fieldVal = field.attr("fieldVal");
			var editTag = field.hasClass(editClass);
			var browseTag = field.hasClass(browseClass);
			var addTag = field.hasClass(addClass);
			if (fieldVal != null && typeof (fieldVal) != 'undefined') {
				fieldVal = eval("(" + fieldVal + ")");
			} else {
				return null;
			}
			var obj = new Object();
			obj.displayName = fieldVal.displayName;
			obj.name = fieldVal.name;
			var tag = true;
			switch (fieldVal.inputType) {
			case "text":
			case "textarea":
				if (editTag) {
					obj.value = field.find("#" + fieldVal.name).val();
				} else if (browseTag) {
					obj.value = fieldVal.value;
				} else if (addTag) {
					obj.value = field.find("#" + fieldVal.name).val();
				}
				break;
			case "select":
				if (editTag) {
					obj.value = field.find(
							"#" + fieldVal.name + " option:selected").attr(
							"val4cal");
				} else if (browseTag) {
					obj.value = field.find("#" + fieldVal.name).attr("val4cal");
				}
				break;
			default:
				tag = false;
			}
			if (obj.value != undefined) {
				obj.value = obj.value.replace("\r\n", ";");
				obj.value = obj.value.replace("\n", ";");
			}
			return obj;
		}

		function setUpFieldValue2(field, value, displayValue, index) {
			var fieldVal = field.attr("fieldVal");
			var editTag = field.hasClass(editClass);
			var browseTag = field.hasClass(browseClass);
			var addTag = field.hasClass(addClass);
			if (fieldVal != null && typeof (fieldVal) != 'undefined') {
				fieldVal = eval("(" + fieldVal + ")");
			} else {
				return null;
			}
			var tag = true;
			switch (fieldVal.inputType) {
			case "text":
			case "textarea":
				if (editTag) {
					field.find("#" + fieldVal.name).val(value);
					field.find("#" + fieldVal.name).trigger("blur");
				} else if (addTag) {
					field.find("#" + fieldVal.name).val(
							field.find("#" + fieldVal.name).val() + value);
					field.find("#" + fieldVal.name).trigger("blur");
				}
				break;
			case "date":
				if (editTag) {
					field.find("#" + fieldVal.name).val(value);
					field.find("#" + fieldVal.name).trigger("blur");
				}
				break;
			}
		}
		
			function addOrDelRepeat(name, newLength) {
	var fields = getUpFieldsByFieldval(name);
		var oldLength = fields.length;

	

		var tbody = getUpFieldsByFieldval(name).eq(0).parent();
		while (!tbody.is("tbody")) {
			tbody = tbody.parent();
		}
		for ( var i = 0, length = Math.abs(newLength - oldLength); i < length; i++) {
			if (newLength > oldLength) {
				upWindow.fy_addEmpty(tbody.children().last());
			} else {
				upWindow.fy_delCurrentRepeat(tbody.children().last());
			}
			
		}
	}
		var FactoryId = [];
		var xmlObj = null;
		<!--数量判断-->
		var planidInput = getUpFieldValue(getUpFieldsByFieldval("计划单号")).value;
		var FactoryIdInputArray = getUpFieldsByFieldval("本厂编号");
		var PlanNumberInputArray = getUpFieldsByFieldval("计划单数量");
		function init() {

		}
		function load() {
			if (window.XMLHttpRequest) {
				xmlObj = new XMLHttpRequest();
			} else {
				if (window.ActiveXObject) {
					xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
				} else {
					return;
				}
			}
			xmlObj.onreadystatechange = handleResponse;

			xmlObj.open("get",
					"./oa2mdmController.do?method=writeNewFindeJSP&planidInput="
							+ planidInput, true);
			xmlObj.send();//发送
		}
		function handleResponse() {
			if (xmlObj.readyState == 4) {
				var success = false;
				if (xmlObj.status == 200) {
				//	var datas = eval("[" + xmlObj.responseText + "]");
					var datas = JSON.parse(xmlObj.responseText);
					addOrDelRepeat("本厂编号",datas.length);
					for ( var i=0;i<datas.length;i++) {
					setUpFieldValue2(getUpFieldsByFieldval("本厂编号").eq(i),datas[i].factory_id);
					setUpFieldValue2(getUpFieldsByFieldval("计划单数量").eq(i),datas[i].plan_number);
					setUpFieldValue2(getUpFieldsByFieldval("行号").eq(i),datas[i].line_Number);
					setUpFieldValue2(getUpFieldsByFieldval("工厂").eq(i),datas[i].factory);
					setUpFieldValue2(getUpFieldsByFieldval("产品名称").eq(i),datas[i].product_Name);
					setUpFieldValue2(getUpFieldsByFieldval("计划日期").eq(i),datas[i].plan_Date);
					setUpFieldValue2(getUpFieldsByFieldval("零件号").eq(i),datas[i].part_number);
					setUpFieldValue2(getUpFieldsByFieldval("混箱标识").eq(i),datas[i].box_Identifier);
					setUpFieldValue2(getUpFieldsByFieldval("成品扣库数量").eq(i),datas[i].buckle_number);
					setUpFieldValue2(getUpFieldsByFieldval("行_允差下限").eq(i),datas[i].limit);
					setUpFieldValue2(getUpFieldsByFieldval("行_允差上限").eq(i),datas[i].ceiling);
					setUpFieldValue2(getUpFieldsByFieldval("是否采购").eq(i),datas[i].procurement);
					setUpFieldValue2(getUpFieldsByFieldval("每箱片数").eq(i),datas[i].pieces_number);
					setUpFieldValue2(getUpFieldsByFieldval("请求部门").eq(i),datas[i].department);
					setUpFieldValue2(getUpFieldsByFieldval("计划库存组织").eq(i),datas[i].planned_inventory);
					setUpFieldValue2(getUpFieldsByFieldval("包装材质").eq(i),datas[i].packing_material);
					setUpFieldValue2(getUpFieldsByFieldval("客户号").eq(i),datas[i].customer_number);
					setUpFieldValue2(getUpFieldsByFieldval("客户名称").eq(i),datas[i].customer_name);
					setUpFieldValue2(getUpFieldsByFieldval("发运地址").eq(i),datas[i].shipping_address);
					setUpFieldValue2(getUpFieldsByFieldval("允差下限").eq(i),datas[i].tolerance_limit);
					setUpFieldValue2(getUpFieldsByFieldval("允差上限").eq(i),datas[i].upper_tolerance);
					}
					success = true
/* 				if (datas.length == 1) {
						var materialMap = datas[0];
						for (var i = 0; i < FactoryIdInputArray.length; i++) {
							var material = materialMap["planid"
									+ getUpFieldValue(planidInput).value];														
							if (material) {
							setUpFieldValue2(FactoryIdInputArray.eq(i),
										material["factory_id"]);
								setUpFieldValue2(PlanNumberInputArray.eq(i),
										material["plan_number"]);
							}
							success = true;
						}
					} */
				}
				if (!success) {
					alert("请检查输入的计划单号和本厂编号 ");
				}
				fy_dialog_close();
			}
		}
		init();//初始化
		load();//加载
	</script>
</body>
</html>
